package com.gkd.controller.regular;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gkd.constant.StatusContant;
import com.gkd.pojo.dto.CategoryDTO;
import com.gkd.pojo.dto.CategoryPageQueryDTO;
import com.gkd.pojo.entity.Category;
import com.gkd.pojo.vo.CategoryVO;
import com.gkd.result.PageResult;
import com.gkd.result.Result;
import com.gkd.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类相关接口
 */
@RestController("regularCategoryController")
@CrossOrigin
@Slf4j
@RequestMapping("/regular/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;


    /**
     * 获取类别列表
     * @return
     */
    @GetMapping
    public Result<List<Category>> list(){
        log.info("获取类别列表");
        LambdaQueryWrapper<Category> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Category::getStatus, StatusContant.CATEGORY_TRUE);
        List<Category> list = categoryService.list(wrapper);
        return Result.success(list);
    }

    /**
     * 根据id查找分类
     * @param categoryId
     * @return
     */
    @GetMapping("/{categoryId}")
    public Result<CategoryVO> getByid(@PathVariable Integer categoryId){
        log.info("根据id查找分类:{}",categoryId);

        CategoryVO categoryVO = new CategoryVO();
        Category category = categoryService.getById(categoryId);
        BeanUtils.copyProperties(category,categoryVO);

        return Result.success(categoryVO);
    }



}
